package main

import "fmt"

type Person struct {
	name string
	sex byte
	age int
}

type Student struct {
	Person	//匿名字段,默认Student就包含了Person所有字段
	id int
	addr string
	name string //和Person中name同名
}
func main() {
	var s1 Student
	//给成员赋值
	s1.name = "mike"
	s1.sex = 'm'
	s1.age = 18
	s1.id = 1
	s1.addr = "sz"
	fmt.Println(s1)

	var s2 Student
	s2.Person = Person{"lily", 'f', 19}
	s2.id = 2
	s2.addr = "bj"
	fmt.Println(s2)

	var s Student //变量声明
	//给Student的name,还是给Person赋值
	s.name = "mike"
	fmt.Printf("s=%+v\n", s)
	//默认只会给最外层的成员赋值
	//给匿名同名成员赋值,需要显式调用
	s.Person.name="yoyo"
	fmt.Printf("s=%+v\n", s)
}
